package com.example.shop_2207

import android.os.Build
import android.view.View
import android.webkit.WebChromeClient
import android.webkit.WebView
import android.webkit.WebViewClient
import androidx.annotation.RequiresApi
import com.example.shop_2207.databinding.ActivityWebviewBinding
import com.example.shop_2207.mvvm.BaseViewActivity


class WebviewActivity : BaseViewActivity<ActivityWebviewBinding>() {
    override fun getLayout(): Int  = R.layout.activity_webview

    @RequiresApi(Build.VERSION_CODES.O)
    override fun initView() {
        val url:String = intent.extras?.getString("url").toString()
        binding.wv.loadUrl(url)
        binding.wv.webViewClient = WebViewClient()//在App内打开一个网页
        //显示加载网页的进度条--加载完后消失
        val client:WebChromeClient = object :WebChromeClient(){
            override fun onProgressChanged(view: WebView?, newProgress: Int) {
                super.onProgressChanged(view, newProgress)
                binding.pb.progress = newProgress
                if(newProgress==100){
                    binding.pb.visibility = View.GONE//不显示不占位
                }
            }
        }
        binding.wv.webChromeClient = client
        binding.wv.settings.javaScriptEnabled = true//允许和js交互


    }

    override fun initData() {

    }

}